<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Coin_packages_entity{
	var $id = 0;
	var $package = "";
	var $coin = "";
	var $cost = 0;
	var $type = "";
	
	function __destruct() {}
	function __construct() {}
    
	function init($cmd, $input)
	{
		$ci=& get_instance();
		
		if($cmd == 'id')
		{
			$result = $ci->db->where('id',$input)->get(TBL_COIN_PACKAGES)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->package = $result[0]->package;
			$this->coin = $result[0]->coin;
			$this->cost = $result[0]->cost;
			$this->type = $result[0]->type;
			
			return $this;
		}
		return false;
	}
	
	function setPackage($input){ $this->package=$input; }
	function setCoin($input){ $this->coin=$input; }
	function setCost($input){ $this->cost=$input; }
	function setType($input){ $this->type=$input; }
	
	function getId(){ return $this->id; }
	function getPackage(){ return $this->package; }
	function getCoin(){ return $this->coin; }
	function getCost(){ return $this->cost; }
	function getType(){ return $this->type; }
	
	function update()
	{
		$ci=& get_instance();
		 
		$ci->db->set('package', $this->package);
		$ci->db->set('coin', $this->coin);
		$ci->db->set('cost', $this->cost);
		$ci->db->set('type', $this->type);
		
		$ci->db->where('id', $this->id)->update(TBL_COIN_PACKAGES);
	}
	
	function createNewEntity(){
		$ci=& get_instance();
		
		$ci->db->set('package', '');
		$ci->db->insert(TBL_COIN_PACKAGES);
		
		return $ci->db->insert_id();
	}
	
	function getListCoinPackages(){
		$ci=& get_instance();
		return $ci->db->order_by('type')->get(TBL_COIN_PACKAGES)->result();
	}
	
	function getCoinPackagesType($type='online'){
		$ci=& get_instance();
		return $ci->db->where('type',$type)->get(TBL_COIN_PACKAGES)->result();
	}

}
